#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<signal.h>
#include<wait.h>
#include<sys/time.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>

int main(int argc, char *args[])
{	
	int pid, i;
	for(i = 0; i < 2; i ++){
		pid = fork();
		if(!pid) break;
	}
	if(i == 1){
		sleep(5);
		exit(i);
	}
	else if(i == 0){
		exit(i);
	}
	else if(i == 2){
		int w_status, ret;
		while((ret = waitpid(0, &w_status, WNOHANG)) != -1)
		{
			printf("ret is %d\n", ret);
			if(WIFEXITED(w_status)){
				printf("exit by %d, w_statu is %d\n", WEXITSTATUS(w_status), w_status);
				sleep(1);
			}
		}
	}
}	
